home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr43 / ppl4p10.zip / OPCODES.PAS < prev    next >
Pascal/Delphi Source File  |  1995-02-20  |  7KB  |  224 lines

  1. (* opcodes.pas *)
  2.  
  3. unit opcodes;
  4.  
  5. interface
  6.  
  7.   type
  8.     String4 = String[4];
  9.     String8 = String[8];
  10.   const
  11.     NO_REF   = 0;
  12.     CODE_REF = 1;
  13.     DATA_REF = 2;
  14.   const
  15.     OPC_HALT    =  0;
  16.     OPC_STATUS  =  1;
  17.     OPC_RETURN  =  2;
  18.     OPC_NOP     =  3;
  19.     OPC_DEBUG   =  4;
  20.     OPC_XXX_5   =  5;
  21.     OPC_XXX_6   =  6;
  22.     OPC_XXX_7   =  7;
  23.     OPC_CALL    =  8;
  24.     OPC_LOOP    =  9;
  25.     OPC_IFTRUE  = 10;
  26.     OPC_IFFALSE = 11;
  27.     OPC_GOTO    = 12;
  28.     OPC_BAUD    = 13;
  29.     OPC_DATABITS= 14;
  30.     OPC_STOPBITS= 15;
  31.     OPC_PARITY  = 16;
  32.     OPC_QUIET   = 17;
  33.     OPC_HANGUP  = 18;
  34.     OPC_REPLY   = 19;
  35.     OPC_DELAY   = 20;
  36.     OPC_SETCOUNT= 21;
  37.     OPC_SETWAIT = 22;
  38.     OPC_SAY     = 23;
  39.     OPC_WAITFOR = 24;
  40.     OPC_SETPACE = 25;
  41.     OPC_SETCASE = 26;
  42.     OPC_ACCEPT  = 27;
  43.     OPC_PROTOCOL= 28;
  44.     OPC_SEND    = 29;
  45.     OPC_RECEIVE = 30;
  46.     OPC_TEST    = 31;
  47.     OPC_IF      = 32;
  48.     OPC_IFNOT   = 33;
  49.     OPC_XXX_34  = 34;
  50.     OPC_XXX_35  = 35;
  51.     OPC_XXX_36  = 36;
  52.     OPC_XXX_37  = 37;
  53.     OPC_XXX_38  = 38;
  54.     OPC_XXX_39  = 39;
  55.     OPC_XXX_40  = 40;
  56.     OPC_USER1   = 41;
  57.     OPC_USER2   = 42;
  58.     OPC_USER3   = 43;
  59.     OPC_USER4   = 44;
  60.     OPC_USER5   = 45;
  61.     OPC_USER6   = 46;
  62.     OPC_USER7   = 47;
  63.     OPC_USER8   = 48;
  64.  
  65.     NBR_OPCODES = 49;
  66.  
  67.   function MatchOpCode(Opcode:Integer):Integer;
  68.   function MatchOpText(Text:String8):Integer;
  69.   function GetOpCode(Index:Integer):Integer;
  70.   function GetOpText(Index:Integer):String8;
  71.   function GetOperType(Index:Integer):Integer;
  72.   function GetOperText(Index:Integer):String8;
  73.  
  74. implementation
  75.  
  76.   const
  77.     REF_HALT    = NO_REF;
  78.     REF_STATUS  = NO_REF;
  79.     REF_RETURN  = NO_REF;
  80.     REF_NOP     = NO_REF;
  81.     REF_DEBUG   = NO_REF;
  82.     REF_CALL    = CODE_REF;
  83.     REF_LOOP    = CODE_REF;
  84.     REF_IFTRUE  = CODE_REF;
  85.     REF_IFFALSE = CODE_REF;
  86.     REF_GOTO    = CODE_REF;
  87.     REF_DELAY   = DATA_REF;
  88.     REF_BAUD    = DATA_REF;
  89.     REF_DATABITS= DATA_REF;
  90.     REF_STOPBITS= DATA_REF;
  91.     REF_PARITY  = DATA_REF;
  92.     REF_QUIET   = DATA_REF;
  93.     REF_HANGUP  = DATA_REF;
  94.     REF_REPLY   = DATA_REF;
  95.     REF_SETCOUNT= DATA_REF;
  96.     REF_SETWAIT = DATA_REF;
  97.     REF_SAY     = DATA_REF;
  98.     REF_WAITFOR = DATA_REF;
  99.     REF_SETPACE = DATA_REF;
  100.     REF_SETCASE = DATA_REF;
  101.     REF_PROTOCOL= DATA_REF;
  102.     REF_SEND    = DATA_REF;
  103.     REF_RECEIVE = DATA_REF;
  104.     REF_IF      = DATA_REF;
  105.     REF_IFNOT   = DATA_REF;
  106.     REF_TEST    = DATA_REF;
  107.     REF_ACCEPT  = DATA_REF;
  108.     REF_USER    = DATA_REF;
  109.  
  110.  
  111.   RefText : array[0..2] of String4 = ('NONE', 'CODE', 'DATA');
  112.  
  113. type
  114.   OpcodeRec = record
  115.     Opcode   : Word;
  116.     OperType : Byte;
  117.     Text     : String8;
  118.   end;
  119.  
  120. const OpcodeList : array[0..NBR_OPCODES-1] of OpcodeRec
  121.   =((Opcode:OPC_HALT;    OperType:REF_HALT;    Text:'HALT'),
  122.     (Opcode:OPC_STATUS;  OperType:REF_STATUS;  Text:'STATUS'),
  123.     (Opcode:OPC_RETURN;  OperType:REF_RETURN;  Text:'RETURN'),
  124.     (Opcode:OPC_NOP;     OperType:REF_NOP;     Text:'NOP'),
  125.     (Opcode:OPC_DEBUG;   OperType:REF_DEBUG;   TEXT:'DEBUG'),
  126.     (Opcode:0;           OperType:0;           TEXT:''),
  127.     (Opcode:0;           OperType:0;           TEXT:''),
  128.     (Opcode:0;           OperType:0;           TEXT:''),
  129.     (Opcode:OPC_CALL;    OperType:REF_CALL;    Text:'CALL'),
  130.     (Opcode:OPC_LOOP;    OperType:REF_LOOP;    Text:'LOOP'),
  131.     (Opcode:OPC_IFTRUE;  OperType:REF_IFTRUE;  Text:'IFTRUE'),
  132.     (Opcode:OPC_IFFALSE; OperType:REF_IFFALSE; Text:'IFFALSE'),
  133.     (Opcode:OPC_GOTO;    OperType:REF_GOTO;    Text:'GOTO'),
  134.     (Opcode:OPC_BAUD;    OperType:REF_BAUD;    Text:'BAUD'),
  135.     (Opcode:OPC_DATABITS;OperType:REF_DATABITS;Text:'DATABITS'),
  136.     (Opcode:OPC_STOPBITS;OperType:REF_STOPBITS;Text:'STOPBITS'),
  137.     (Opcode:OPC_PARITY;  OperType:REF_PARITY;  Text:'PARITY'),
  138.     (Opcode:OPC_QUIET;   OperType:REF_QUIET;   Text:'QUIET'),
  139.     (Opcode:OPC_HANGUP;  OperType:REF_HANGUP;  Text:'HANGUP'),
  140.     (Opcode:OPC_REPLY;   OperType:REF_REPLY;   Text:'REPLY'),
  141.     (Opcode:OPC_DELAY;   OperType:REF_DELAY;   Text:'DELAY'),
  142.     (Opcode:OPC_SETCOUNT;OperType:REF_SETCOUNT;Text:'SETCOUNT'),
  143.     (Opcode:OPC_SETWAIT; OperType:REF_SETWAIT; Text:'SETWAIT'),
  144.     (Opcode:OPC_SAY;     OperType:REF_SAY;     Text:'SAY'),
  145.     (Opcode:OPC_WAITFOR; OperType:REF_WAITFOR; Text:'WAITFOR'),
  146.     (Opcode:OPC_SETPACE; OperType:REF_SETPACE; Text:'SETPACE'),
  147.     (Opcode:OPC_SETCASE; OperType:REF_SETCASE; Text:'SETCASE'),
  148.     (Opcode:OPC_ACCEPT;  OperType:REF_ACCEPT;  TEXT:'ACCEPT'),
  149.     (Opcode:OPC_PROTOCOL;OperType:REF_PROTOCOL;Text:'PROTOCOL'),
  150.     (Opcode:OPC_SEND;    OperType:REF_SEND;    Text:'SEND'),
  151.     (Opcode:OPC_RECEIVE; OperType:REF_RECEIVE; Text:'RECEIVE'),
  152.     (Opcode:OPC_TEST;    OperType:REF_TEST;    Text:'TEST'),
  153.     (Opcode:OPC_IF;      OperType:REF_IF;      Text:'IF'),
  154.     (Opcode:OPC_IFNOT;   OperType:REF_IFNOT;   Text:'IFNOT'),
  155.     (Opcode:0;           OperType:0;           TEXT:''),
  156.     (Opcode:0;           OperType:0;           TEXT:''),
  157.     (Opcode:0;           OperType:0;           TEXT:''),
  158.     (Opcode:0;           OperType:0;           TEXT:''),
  159.     (Opcode:0;           OperType:0;           TEXT:''),
  160.     (Opcode:0;           OperType:0;           TEXT:''),
  161.     (Opcode:0;           OperType:0;           TEXT:''),
  162.     (Opcode:OPC_USER1;   OperType:REF_USER;    Text:'USER1'),
  163.     (Opcode:OPC_USER2;   OperType:REF_USER;    Text:'USER2'),
  164.     (Opcode:OPC_USER3;   OperType:REF_USER;    Text:'USER3'),
  165.     (Opcode:OPC_USER4;   OperType:REF_USER;    Text:'USER4'),
  166.     (Opcode:OPC_USER5;   OperType:REF_USER;    Text:'USER5'),
  167.     (Opcode:OPC_USER6;   OperType:REF_USER;    Text:'USER6'),
  168.     (Opcode:OPC_USER7;   OperType:REF_USER;    Text:'USER7'),
  169.     (Opcode:OPC_USER8;   OperType:REF_USER;    Text:'USER8')
  170.    );
  171.  
  172.  function MatchOpCode(Opcode:Integer):Integer;
  173.  var
  174.    i : Integer;
  175.  begin
  176.   for i := 0 to NBR_OPCODES-1 do
  177.     if OpcodeList[i].Opcode = Opcode then
  178.       begin
  179.         MatchOpCode := i;
  180.         Exit;
  181.       end;
  182.   MatchOpcode := -1;
  183.  end;
  184.  
  185.  function MatchOpText(Text:String8):Integer;
  186.  var
  187.    i : Integer;
  188.  begin
  189.    for i := 0 to NBR_OPCODES-1 do
  190.      if OpcodeList[i].Text = Text then
  191.        begin
  192.          MatchOpText := i;
  193.          Exit;
  194.        end;
  195.    MatchOpText := -1;
  196.  end;
  197.  
  198.  function GetOpCode(Index:Integer):Integer;
  199.  begin
  200.   if Index < NBR_OPCODES then GetOpCode := OpcodeList[Index].Opcode
  201.   else GetOpCode := -1;
  202.  end;
  203.  
  204.  function GetOpText(Index:Integer):String8;
  205.  begin
  206.   if Index < NBR_OPCODES then GetOpText := OpcodeList[Index].Text
  207.   else GetOpText := '';
  208.  end;
  209.  
  210.  function GetOperType(Index:Integer):Integer;
  211.  begin
  212.   if Index < NBR_OPCODES then GetOperType := OpcodeList[Index].OperType
  213.   else GetOperType := -1;
  214.  end;
  215.  
  216.  function GetOperText(Index:Integer):String8;
  217.  begin
  218.   if Index < NBR_OPCODES then GetOperText := RefText[Index]
  219.   else GetOperText := '';
  220.  end;
  221.  
  222. end.
  223.  
  224.